Skip to content

Benchmarks: the one-row terminals of a mapped reader, the shape before the First/Single dedupe - #291

Merged
electricessence merged 1 commit into
masterfrom
bench/one-row-lookup
Dec 2, 2026
Merged

electricessence merged 1 commit into
masterfrom
bench/one-row-lookup

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

A BenchmarkDotNet class family for the one-row terminals, so the planned First/Single change (put their bodies onto the FirstOrDefault/SingleOrDefault ones with one private helper, K-F of the dead-code review) can be measured against the shape they have now. Build-only here: nothing was run as a timed benchmark (that needs a quiet machine), and no BenchmarkDotNet run was made.

What it measures

OneRowInt and OneRowClass (a class with a string), each over an in-memory DataTableReader (no database): the fixed cost of one call, in time and allocated bytes, since a lookup by key is the typical use.

Variant Table Sync Async
hand-written read of the one row, same selector delegate (the baseline of each group) 1 row yes yes
hand-written Single: the row, then a second read to check there is no more (the like-for-like of Single) 1 row yes yes
First, FirstOrDefault 1 row and 100 rows (the terminal must stop after the first) yes yes
Single, SingleOrDefault 1 row yes yes

Results are grouped sync and async, each group against its own baseline. Every async variant has the same shape (one async method that creates, uses and disposes its own reader, returning ValueTask), so the library's calls and the hand-written ones carry the same machinery; every variant returns its row, so the harness consumes it; the memory diagnoser is on. Filters: *OneRowInt*, *OneRowClass*, and within them *Sync_* or *Async_*.

--verify-onerow (no BenchmarkDotNet, nothing measured) checks that every variant gives the row of the hand-written read, twice each, for both row kinds: "one-row variants: all equal".

Checks

  • Release and Debug builds, 0 warnings and 0 errors; Core tests and the samples pass; the Visual Studio solution build has no errors; dotnet format style and analyzers at --severity info report nothing on all 14 projects; the docs build is clean (a benchmark-only change, run through the whole gate anyway).
  • One Haiku reviewer, arbitrated. Fixed: the async library variants went through a wrapper method (one more async state machine than the hand-written read), so every async variant now has the same one-method shape; the hand-written baseline did not do Single's second read, so a hand-written Single was added; the group rule is also on the concrete classes. Not taken: the OneRowChecks exception handling (a throwing variant aborts the check, which is loud enough).

🤖 Generated with Claude Code

…e the First/Single dedupe

A BenchmarkDotNet class family (`OneRowInt`, `OneRowClass`) for the cost of one call of `First`, `FirstOrDefault`, `Single` and `SingleOrDefault`, synchronous and asynchronous, over an in-memory `DataTableReader` (no database): a lookup by key is the typical use, so the fixed cost of one call is what matters, in time and in allocated bytes. Each runs on a table of one row; `First` and `FirstOrDefault` also on a table of 100 rows, where the terminal must stop after the first. A hand-written read of the one row through the same selector delegate is the baseline of each group (synchronous and asynchronous), and a hand-written `Single` (the row, then a second read to check there is no more) is its like-for-like; every async variant has the same shape (one async method that creates, uses and disposes its reader), every variant returns its row so the harness consumes it, and the memory diagnoser is on.

This is the BEFORE shape: the change that would put the `First` and `Single` bodies onto the `FirstOrDefault` and `SingleOrDefault` ones (one private helper, as the dead-code review proposed) is measured against it.

`--verify-onerow` checks, without BenchmarkDotNet, that every variant gives the row of the hand-written read, twice each. Not run as timed benchmarks by this change: that needs a quiet machine.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence merged commit 7938430 into master Dec 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant